package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service//dubbo注解
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;
    //保存用户的方法
    @Override
    public Long save(User user) {
        //mybatis-plus  新增自动保存id
        userMapper.insert(user);
        return user.getId();
    }

    //根据手机号查询用户对象
    @Override
    public User findByPhone(String phone) {
        //拼接条件
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("phone", phone);
        User user = userMapper.selectOne(queryWrapper);
        return user;
    }

    //根据用户id更新手机号
    @Override
    public void updateUserId(User user,String phone) {
        userMapper.updateById(user);

    }
}
